<?php
    /**
     * Created by PhpStorm.
     * User: mybook-lhp
     * Date: 18/7/2
     * Time: 下午3:39
     */

    namespace app\common\controller;

    use app\common\traits\apiinit;
    use app\common\utils\UtilJwt;
    use app\payment\model\WalletProductModel;
    use think\Controller;
    use think\facade\Env;
    use think\facade\Request;

    class API extends Controller
    {

        use apiinit;

        public function _empty($name)
        {
            $this->result('未找到访问地址！');
        }

        /**
         * @throws \think\Exception
         */
        protected function initialize()
        {
            parent::initialize(); // TODO: Change the autogenerated stub
            $token = Env::get('token');
            Env::set('member_id', $token['member_id']);

            if (!Env::get('app_id')) {
                $app_id = $this->request->header('app-id');
                $app_id === null ? $this->error('APPID不存在！') : null;
                Env::set('app_id', $app_id);
            }
        }

        /**
         * 数据验证成功返回验证数据错误返回错误信息
         *
         * @param $data
         * @param $type
         */
        protected function check_validate($data, $type)
        {
            $result = $this->validate($data, $type);
            return (true !== $result) ? $this->error($result) : $data;

        }

        /**
         * 数据验证成功返回验证数据错误返回错误信息
         *
         * @param      $type
         * @param bool $Membe_id
         *
         * @return mixed|void
         */
        protected function check_validate_param($type, $Membe_id = false)
        {

            $data = $this->request->param();
            $data['member_id'] = env('member_id');
            $result = $this->validate($data, $type);

            if (!$Membe_id) {
                unset($data['member_id']);
            }
            return (true !== $result) ? $this->error($result) : $data;
        }

    }